﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using Icst.Leaflike.Logging;

namespace Icst.Leaflike.Searching
{
    public class SAFGWrapper
    {
        private static object _l = new object();
        private static bool _initialized = false;

        public static void Initialize(string fvcacheFile, string specieidlistFile)
        {
            if (!_initialized)
            {
                lock (_l)
                {
                    if (!_initialized)
                    {
                        int s = LoadFVCache(fvcacheFile);
                        Logger.Info("LoadFVCache" + s);
                        int t = LoadSpecieIDList(specieidlistFile);
                        Logger.Info("LoadSpecieIDList " + t);

                        _initialized = true;
                    }
                }
            }
        }

        [DllImport("dllexport.dll", EntryPoint = "LoadSpecieIDList", CharSet = CharSet.Auto)]
        internal static extern int LoadSpecieIDList(string filename);

        [DllImport("dllexport.dll", EntryPoint = "LoadFVCache", CharSet = CharSet.Auto)]
        internal static extern int LoadFVCache(string filename);

        //[DllImport("dllexport.dll", EntryPoint = "test_Rgn", CharSet = CharSet.Auto)]
        //private static extern int test_Rgn(int[] plantID, int num);

        [DllImport("dllexport.dll", EntryPoint = "LeafRgn", CharSet = CharSet.Auto)]
        internal static extern int LeafRgn(int[] x, int[] y, int contour_length, int[] plantID, int num);

        [DllImport("dllexport.dll", EntryPoint = "LeafContourByFile", CharSet = CharSet.Auto)]
        internal static extern int LeafContourByFile(string imageFile, int[] x, int[] y, int max_length);
    }
}
